<?php
class MY_Controller extends CI_Controller {
function __construct()
	{
		parent::__construct();
	}
}

class Admin_Controller extends MY_Controller {
	public $template_data = array(
		'tmp_header'	=>	'layout/admin/include/header',
		'tmp_sidebar'	=>	'layout/admin/include/left',
		'tmp_footer'	=>	'layout/admin/include/footer',
		'tmp_nav'	=>	'layout/admin/include/nav',
		'main_header'	=>	'layout/admin/include/main_header'
	);
	public $resource_admin = 'RESOURCE/static/';
	function __construct() {
        parent::__construct();
        $this->load->helper('util_helper');
        $this->load->model('mhtml');
        $this->load->library(array('ion_auth','form_validation'));
        $this->load->helper(array('url','language'));
        // $this->form_validation->set_error_delimiters($this->config->item('error_start_delimiter', 'ion_auth'), $this->config->item('error_end_delimiter', 'ion_auth'));
        // $this->lang->load('auth');
        // if (!$this->ion_auth->logged_in())
        // {
        //     //redirect them to the login page
        //     redirect('auth/login', 'refresh');
        // }
    }	

    function clean_search(){
		setcookie ("search", "", time() - 3600);
		//prd($this->input->cookie('search'));
		$this->load->library('user_agent');
		if ($this->agent->is_referral())
		{
			redirect($this->agent->referrer());
		}
		else {
			redirect($this->url_index);
		}
	}

	function search_allpost(){
		$post = $this->input->post();
		$data = array();
		$this->load->library('user_agent');
		if($post){
			$s = $this->input->post('txtSearch');
			$field = $this->input->post('selFieldSearch');
			$condition = $this->input->post('selCondition');
			$category = $this->input->post('selCategory');
			$creator = $this->input->post('selCreator');
			$time_start = $this->input->post('time_start');
			$time_end = $this->input->post('time_end');

			if(!$time_start) $time_start = '';
			else
				$time_start = strtotime($time_start);

			if(!$time_end) $time_end = '';
			else
				$time_end = strtotime($time_end);

			$cookie_val = $field.'|'.($s!=''?$s:'').'|'.$condition.'|'.@implode(',', $category).'|'.@implode(',', $creator).'|'.$time_start.'|'.$time_end;
			setcookie("search",	$field."|".($s!=''?$s:'').'|'.$condition.'|'.@implode(',', $category).'|'.@implode(',', $creator).'|'.$time_start.'|'.$time_end, time() + 7200);
			if ($this->agent->is_referral())
			{
			    redirect($this->agent->referrer());
			}
			else {
				redirect($this->url_index);
			}
			
		}
		else if($this->input->cookie('search')) {
			$str = $this->input->cookie('search');
			$str = explode("|",$str);
			if(count($str) >1){
				$field = $str[0];
				$s = $str[1];
				$condition = $str[2];
				if($str[3] !='')
					$cates = explode(',', $str[3]);
				if($str[4] !='')
					$creators = explode(',', $str[4]);
				$time_start = $str[5];
				$time_end = $str[6];
			}
			else {
				return $data;
			}
		}
			if(isset($s) && $s !=''){
				if($condition == '='){
					$this->db->where($field,$s);
					return $data;
				}
				else {
					$this->db->like($field,$s);
					return $data;
				}
			}
			if(isset($cates) && count($cates)>0){
				$this->db->join('post_category', 'post_category.pos_id = post.pos_id');
				$this->db->where_in('post_category.cat_id', $cates);	
			}

			if(isset($creators) && count($creators)>0){
				$this->db->where_in('post.pos_user_create',$creators);
			}

			if(isset($time_start) && isset($time_end) && $time_start !='' && $time_end !=''){
				$this->db->where('post.pos_date_create >=',$time_start);
				$this->db->where('post.pos_date_create <=',$time_end);
			}
		return $data;
	}
}

/* End of file Admin_Controller.php */
/* Location: ./application/core/MY_Controller.php */